#ifndef IMAGEITEM_H
#define IMAGEITEM_H

#include <QGraphicsItem>
#include <QPainter>

class ImageItem : public QGraphicsItem
{
public:
    explicit ImageItem(const QImage& image,const QRect& rect):
        m_image(image),
        m_rect(rect)
    {
    }

    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
        painter->drawImage(m_rect,m_image);
    }
    virtual QRectF boundingRect() const
    {
        if (m_image.isNull())
            return QRectF();
        return QRectF(QPointF(0.0,0.0), m_image.size());
    }

    void setImage(const QImage &image)
    {
        m_image = image;
        update();
    }

    void setRect(const QRect& rect)
    {
       m_rect = rect;
       update();
    }

public:
    QImage  m_image;
    QRect   m_rect;
};

#endif // IMAGEITEM_H
